/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lucene.simple.spellCheck;

/**
 *
 * @author Content Pilot
 */
public class SpellCheckerTest {
    

      
    public String didYouMean(String dir, String wordForSuggestion, int suggestionsNumber ) {
  
        String suggestionWord = "oops";
        try{
            java.io.File indexDir = new java.io.File(dir);
            
            Object obj = org.apache.lucene.store.FSDirectory.open(indexDir);
            
            org.apache.lucene.store.Directory directory = org.apache.lucene.store.FSDirectory.open(indexDir);
            org.apache.lucene.search.spell.SpellChecker spellChecker = new org.apache.lucene.search.spell.SpellChecker(directory);
            spellChecker.indexDictionary(
                    new org.apache.lucene.search.spell.PlainTextDictionary(new java.io.File("c:/spellchecker/dict.txt")));
        String[] suggestions = spellChecker.suggestSimilar(wordForSuggestion, 1);
        if (suggestions != null && suggestions.length > 0) {
            for (String word : suggestions) {
                System.out.println("Did you mean: " + word);
                suggestionWord = word;
            }
        } else {
            System.out.println(" No suggestions found for word: " + wordForSuggestion);
        }              
        } catch ( Exception e ){
            System.out.println(e.getStackTrace());
        }

  return suggestionWord;
        

        
    }
}
